from rest_framework.views import APIView
from django.shortcuts import render,redirect,HttpResponse
from dal import models
from django.http import JsonResponse


class LookGet(APIView):


    def post(self,request):

        username = str(request.data.get("username"))

        news_id = str(request.data.get("news_id"))

        message = {}

        user_id = models.UserInfo.objects.get(username=username).pk
        try:
            models.Look.objects.create(user_id=user_id,search_id=news_id)

            message['code'] = 200
            return JsonResponse(message)
        except Exception as e:
            print(e)
            message['code'] = 444
            return JsonResponse(message)